package javolution.context;

/* loaded from: classes2.dex */
public abstract class Allocator<T> {
    protected boolean keepInQueue;
    protected T[] queue = (T[]) new Object[16];
    protected int queueSize;
    protected Thread user;

    private final T removeLast() {
        T[] tArr = this.queue;
        int i = this.queueSize - 1;
        this.queueSize = i;
        T t = tArr[i];
        tArr[this.queueSize] = null;
        return t;
    }

    protected abstract T allocate();

    public final T next() {
        int i = this.queueSize;
        if (i > 0) {
            if (this.keepInQueue) {
                T[] tArr = this.queue;
                int i2 = i - 1;
                this.queueSize = i2;
                return tArr[i2];
            }
            return removeLast();
        }
        return allocate();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public abstract void recycle(T t);

    /* JADX INFO: Access modifiers changed from: package-private */
    public void resize() {
        T[] tArr = this.queue;
        T[] tArr2 = (T[]) new Object[tArr.length * 2];
        System.arraycopy(tArr, 0, tArr2, 0, tArr.length);
        this.queue = tArr2;
    }
}
